package com.ldc.wandroid.adapter;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ldc.common.common.CommonRecyclerView;
import com.ldc.common.common.CommonRecyclerViewHolder;
import com.ldc.common.common.CommonRowClick;
import com.ldc.wandroid.R;

public class ProjectTabTitleAdapter extends CommonRecyclerView<String> {
    private int selectPosition = 0;
    private CommonRowClick<Integer> onRow;

    public ProjectTabTitleAdapter() {
        super(R.layout.common_layout_tv_name);
    }


    public void addRowListener(CommonRowClick<Integer> onRow) {
        this.onRow = onRow;
    }


    public void setSelectPosition(int index) {
        selectPosition = index;
        notifyDataSetChanged();
    }

    @Override
    protected void convert2Data(@NonNull CommonRecyclerViewHolder holder, String source, int position) {
        boolean hasCurrent = selectPosition == position;
        TextView tv = (TextView) holder.findViewById(R.id.tv_name);
        tv.setText(source);
        tv.setTextColor(hasCurrent ? tv.getResources().getColor(R.color.color_font_select) :
                tv.getResources().getColor(R.color.color_font_main));
        tv.setOnClickListener(view -> {
            if (null != onRow) {
                onRow.onRow(position);
            }
        });
    }
}
